import {
  imageUrl
} from "../../utils/imageutil"
import {
  formatTime,
  is_auth
} from "../../utils/util"

let app = getApp()
Page({

  data: {
    imageUrl,
    flag: true,
    smbox: [{
      title: '品质保障 服务无忧',
      id: 1
    }, {
      title: '48小时专业培训',
      id: 2
    }, {
      title: '标准定价 售后无忧',
      id: 3
    }],
    types: [
      //   {
      //   name:'月嫂',
      //   desc:'照看产妇',
      //   type:1
      // },{
      //   name:'保姆',
      //   desc:'做饭做家务',
      //   type:2
      // },{
      //   name:'钟点工',
      //   desc:'时间灵活',
      //   type:3
      // },{
      //   name:'育婴师',
      //   desc:'照看0-3岁小孩',
      //   type:4
      // },{
      //   name:'育儿嫂',
      //   desc:'照顾婴幼儿',
      //   type:5
      // },{
      //   name:'护工',
      //   desc:'照顾老弱病残',
      //   type:6
      // }
    ],
    work_type: 1, //默认月嫂
    types_curr: 1, //默认月嫂

    types_child_list: [],
    types_child_curr: -1, //护工类型下标

    addressid: '',
    myDefaultAddress: '',

    zhujia: [{
      title: '住家',
      type: 1
    }, {
      title: '不住家',
      type: 0
    }],
    zhujia_curr: -1,
    is_live_room: -1, //1住家 0不住家

    childlist: [{
      num: 0
    }],
    child_situation: '0岁',

    production: '',
    production_num: '',
    is_production: false,

    work_times_start: '', //工作时间

    work_do: '', //工作内容

    working_day_list: [],
    working_day_num: -1,
    working_day: '', //工作天数

    can_do: '', //任职要求

    persion_num_age: '',
    need_age: '',

    birthday_num: '',
    birthday: '', //宝宝生日

    hygiene_list: [],
    hygiene_curr: -1,
    measure: '', //卫生面积

    taste_list: [{
      title: '川湘菜'
    }, {
      title: '江浙菜'
    }, {
      title: '东北菜'
    }, {
      title: '粤菜'
    }],
    taste_curr: -1,
    diet: '',

    multiIndex: [0, 0, 0, 0, 0],
    worktime: '', //服务时间

    money2: '', //工资薪酬

    other_data_list: [],
    other_data: '', //其他福利

    old_situation_list: [],
    old_situation: '', //老人情况

    star_list: [],
    star_curr: -1,
    total: 0,

    is_store: false, //是否家政端派单
    is_specia: false, //孩子优秀
    work_special_id: '',
    production_mode: '',
    fetus: '',
    gznative_place: '',
    production_mode_list: [{
      name: '剖腹产'
    }, {
      name: '顺产'
    }],
    fetus_list: [{
      name: '单胞胎'
    }, {
      name: '双胞胎'
    }],
    gznative_place_list: [],
    production_mode_num: -1,
    fetus_num: -1,
    gznative_place_num: -1,

    store_to_user: {
      id: '',
      name: ''
    }, //家政公司帮下单用户信息

    gqm: '', //签名地址

    education_list: [],
    employment_list: [],
    native_place_list: [],
    sex_list: [],
    work_experience_list: [],

    education: '',
    employment: '',
    native_place: '',
    sex: '',
    work_experience: '',

    education_num: -1,
    employment_num: -1,
    native_place_num: -1,
    sex_num: -1,
    work_experience_num: -1,

    expectation: 1, //1 = 7天 2 = 15天 3 = 30天
    expectation_list: [{
      name: '7天',
      type: 1
    }, {
      name: '15天',
      type: 2
    }, {
      name: '30天',
      type: 3
    }],

    release_work_id: '',
    paytype_list: [{
      paytype: 1,
      title: "微信"
    }],
    has_jump: false,
    show_code_img: false,

  },

  get_paytype() {
    getApp().globalData.post({
      url: '/api/applet.ouyoung/paytype.html',
      data: {
        storeid: 10
      }
    }, true).then(res => {
      this.setData({
        // paytype_list: res.data.data
      })
    })
  },

  SaveNeedWork() {
    let obj = {}
    if (this.data.is_store) {
      obj = {
        need_type: 2,
        store_id: wx.getStorageSync('merchant').admin.storeid
      }
    } else {
      obj = {
        need_type: 1,
      }
    }
    // 保存需求
    app.globalData.post({
      data: {
        do: 'SaveNeedWork',
        a: "wxapp2",
        ...obj,
        uid: this.data.is_store ? this.data.store_to_user.id : wx.getStorageSync('userInfo').id,
        addressid: this.data.addressid,
        work_type: this.data.work_type,
        is_live_room: this.data.is_live_room,
        work_times_start: this.data.work_times_start,
        work_do: this.data.work_do,
        can_do: this.data.can_do,
        persion_num_age: this.data.persion_num_age,
        measure: this.data.measure,
        diet: this.data.diet,
        worktime: this.data.worktime,
        money2: this.data.money2,
        other_data: this.data.other_data,
        production: this.data.production,
        old_situation: this.data.old_situation,
        child_situation: this.data.child_situation,
        earnest_type: this.data.star_curr,
        earnest_price: this.data.total,
        openid: wx.getStorageSync('userInfo').openid,
        child_work_type: this.data.types_child_curr == -1 ? '' : this.data.types_child_list[this.data.types_child_curr].type,
        working_day: this.data.working_day,
        education: this.data.education,
        native_place: this.data.native_place,
        need_age: this.data.need_age,
        employment: this.data.employment,
        work_experience: this.data.work_experience,
        sex: this.data.sex,
        birthday: this.data.birthday,
        expectation: this.data.expectation,
      }
    }).then((res) => {

    })
  },
  onUnload() {
    this.SaveNeedWork()
  },
  GetNeedWork() {
    // 获取保存的需求
    return new Promise((reslove, reject) => {
      let obj = {}
      if (this.data.is_store) {
        obj = {
          need_type: 2,
          store_id: wx.getStorageSync('merchant').admin.storeid
        }
      } else {
        obj = {
          need_type: 1,
        }
      }
      app.globalData.post({
        data: {
          do: 'GetNeedWork',
          a: "wxapp2",
          ...obj,
          uid: wx.getStorageSync('userInfo').id
        }
      }).then((res) => {
        if (res.data.code == 0 || this.data.is_specia) {
          reject()
          return
        }
        let data = JSON.parse(res.data.data)

        this.setData({
          work_type: data.work_type,
          is_live_room: data.is_live_room,
          work_times_start: data.work_times_start,
          work_do: data.work_do,
          can_do: data.can_do,
          persion_num_age: data.persion_num_age,
          measure: data.measure,
          diet: data.diet,
          worktime: data.worktime,
          money2: data.money2,
          other_data: data.other_data,
          production: data.production,
          old_situation: data.old_situation,
          child_situation: data.child_situation,
          star_curr: data.earnest_type,
          total: data.earnest_price,
          working_day: data.working_day,
          education: data.education,
          native_place: data.native_place,
          need_age: data.need_age,
          employment: data.employment,
          work_experience: data.work_experience,
          sex: data.sex,
          birthday: data.birthday,
          expectation: data.expectation
        })

        wx.setStorageSync('work_do', data.work_do);
        wx.setStorageSync('can_do', data.can_do);
        wx.setStorageSync('persion_num_age', data.persion_num_age);
        wx.setStorageSync('working_day', data.working_day);
        wx.setStorageSync('need_age', data.need_age);

        // 家政员类型
        this.AuntType().then(() => {
          this.setData({
            types_curr: data.work_type,
          })
          this.data.types_child_list.forEach((v, i) => {
            if (data.child_work_type == v.type) {
              this.setData({
                types_child_curr: i
              })
            }
          })
        })


        // 住家
        this.data.zhujia.forEach((v, i) => {
          if (v.type == data.is_live_room) {
            this.setData({
              zhujia_curr: i
            })
          }
        })

        // 小朋友情况
        let childlist = []
        let child_situation = data.child_situation.split(',')
        if (child_situation.length > 0) {
          child_situation.forEach((v, i) => {
            childlist.push({
              num: Number(v.split('岁')[0])
            })
          })
          this.setData({
            childlist
          })
        }

        // 家庭面积
        this.Measure().then(() => {
          this.data.hygiene_list.forEach((v, i) => {
            if (v.title == data.measure) {
              this.setData({
                hygiene_curr: i
              })
            }
          })
        })

        // 老人情况
        this.get_old_situation().then(() => {
          let old_situation_arr = data.old_situation.split(',')
          this.data.old_situation_list.forEach((v, i) => {
            old_situation_arr.forEach((vv, ii) => {
              if (v.title == vv) {
                this.setData({
                  ['old_situation_list[' + i + '].select']: true
                })
              }
            })
          })
        })

        // 口味要求
        this.AuntDietType().then(() => {
          let diet_arr = data.diet.split(',')
          this.data.taste_list.forEach((v, i) => {
            diet_arr.forEach((vv, ii) => {
              if (v.title == vv) {
                this.setData({
                  ['taste_list[' + i + '].select']: true
                })
              }
            })
          })
        })

        //其他福利
        this.get_other_data().then(() => {
          let other_data_arr = data.other_data.split(',')
          this.data.other_data_list.forEach((v, i) => {
            other_data_arr.forEach((vv, ii) => {
              if (v.title == vv) {
                this.setData({
                  ['other_data_list[' + i + '].select']: true
                })
              }
            })
          })
        })

        // 学历 籍贯 用工时间 工作经验 性别
        this.GetQuantity().then(() => {
          this.data.education_list.forEach((v, i) => {
            if (data.education == v.id) {
              this.setData({
                education_num: i
              })
            }
          })

          this.data.native_place_list.forEach((v, i) => {
            if (data.native_place == v.id) {
              this.setData({
                native_place_num: i
              })
            }
          })

          this.data.sex_list.forEach((v, i) => {
            if (data.sex == v.id) {
              this.setData({
                sex_num: i
              })
            }
          })

          this.data.employment_list.forEach((v, i) => {
            if (data.employment == v.id) {
              this.setData({
                employment_num: i
              })
            }
          })

          this.data.work_experience_list.forEach((v, i) => {
            if (data.work_experience == v.id) {
              this.setData({
                work_experience_num: i
              })
            }
          })

        })


        reslove()
      })
    })

  },



  GetQuantity() {
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: 'GetQuantity',
          a: "wxapp2"
        }
      }).then(res => {
        this.setData({
          education_list: res.data.data.education,
          employment_list: res.data.data.employment,
          native_place_list: res.data.data.native_place,
          gznative_place_list: res.data.data.native_place,
          sex_list: res.data.data.sex,
          work_experience_list: res.data.data.work_experience,
        })
        reslove()
      })
    })
  },

  get_child_situation_val() {
    let arr = []
    this.data.childlist.forEach((v, i) => {
      arr.push(v.num + '岁')
    })
    let val = '';
    val = arr.join(',')
    this.setData({
      child_situation: val
    })
  },

  child_add() {
    this.setData({
      ['childlist[' + this.data.childlist.length + '].num']: 0
    })
    this.get_child_situation_val()
  },
  child_jian(e) {
    let index = e.currentTarget.dataset.index;
    let arr = this.data.childlist;
    arr.splice(index, 1);
    this.setData({
      childlist: arr
    })
    this.get_child_situation_val()
  },
  change_childlist_num_jian(e) {
    let index = e.currentTarget.dataset.index;
    if (this.data.childlist[index].num == 0) {
      return;
    } else {
      this.setData({
        ['childlist[' + index + '].num']: this.data.childlist[index].num - 1
      })
    }
    this.get_child_situation_val()
  },
  change_childlist_num_add(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      ['childlist[' + index + '].num']: this.data.childlist[index].num + 1
    })
    this.get_child_situation_val();
  },

  get_working_day_list() {
    return new Promise((reslove, reject) => {
      let arr = [];
      for (let i = 1; i < 31; i++) {
        arr.push(i)
      }
      this.setData({
        working_day_list: arr
      })
      reslove()
    })
  },

  onLoad(options) {
    wx.removeStorageSync('work_do');
    wx.removeStorageSync('can_do');
    wx.removeStorageSync('persion_num_age');
    wx.removeStorageSync('qm_src');
    wx.removeStorageSync('store_to_user');
    wx.removeStorageSync('stote_user_address');
    wx.removeStorageSync('working_day');
    wx.removeStorageSync('need_age');

    this.get_working_day_list()
    this.get_paytype()

    if (options.is_store) {
      this.setData({
        is_store: true
      })
      wx.setNavigationBarTitle({
        title: '代发需求',
      })
    }

    if (options.is_specia) {
      this.setData({
        is_specia: true,
        work_special_id: options.work_special_id
      })
    }


    this.HouseClass()

    let date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth()
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    this.setData({
      multiIndex: [0, month, day - 1, hour, minute],
      production_start: formatTime(date)
    })

    this.GetNeedWork().catch(() => {
      this.AuntType()
      this.Measure()
      this.AuntDietType()
      this.get_other_data()
      this.GetQuantity()
      this.get_old_situation()
    })

  },

  onShow() {

    if (this.data.has_jump) {
      getApp().showModal('是否已完成支付', true).then(() => {
        getApp().showModal('系统已为您自动推荐家政员', true, '立即查看').then(() => {
          wx.navigateTo({
            url: '/pages/matron/plan?wid=' + this.data.release_work_id
          })
        }).catch(() => {
          wx.navigateBack()
        })
      })
      this.setData({
        has_jump: false
      })
    }

    if (wx.getStorageSync('store_to_user')) {
      this.setData({
        store_to_user: wx.getStorageSync('store_to_user'),
        myDefaultAddress: '',
        addressid: '',
      })
      wx.removeStorageSync('store_to_user')
    } else {
      if (!this.data.is_store) {
        this.MyAddressInfo()
      }
    }
    if (wx.getStorageSync('stote_user_address')) {
      this.setData({
        myDefaultAddress: wx.getStorageSync('stote_user_address'),
        addressid: wx.getStorageSync('stote_user_address').id,
      })
      wx.removeStorageSync('stote_user_address')
    }
    if (wx.getStorageSync('work_do')) {
      this.setData({
        work_do: wx.getStorageSync('work_do')
      })
    }
    if (wx.getStorageSync('can_do')) {
      this.setData({
        can_do: wx.getStorageSync('can_do')
      })
    }
    if (wx.getStorageSync('persion_num_age')) {
      this.setData({
        persion_num_age: wx.getStorageSync('persion_num_age')
      })
    }
    if (wx.getStorageSync('qm_src')) {
      this.setData({
        gqm: wx.getStorageSync('qm_src')
      })
    }
    if (wx.getStorageSync('working_day')) {
      this.setData({
        working_day: wx.getStorageSync('working_day')
      })
    }
    if (wx.getStorageSync('need_age')) {
      this.setData({
        need_age: wx.getStorageSync('need_age')
      })
    }
  },

  AuntType() {
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: "AuntType"
        }
      }).then(res => {
        this.setData({
          types: res.data.result
        })
        res.data.result.forEach((v, i) => {
          if (v.type == 6) {
            this.setData({
              types_child_list: v.child
            })
          }
        })
        reslove()
      })
    })
  },

  AuntDietType() {
    // 获取饮食类型
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: "AuntDietType"
        }
      }).then(res => {
        this.setData({
          taste_list: res.data.result
        })
        reslove()
      })
    })
  },

  Measure() {
    // 房屋面积
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: "Measure"
        }
      }).then(res => {
        this.setData({
          hygiene_list: res.data.result
        })
        reslove()
      })
    })
  },

  get_old_situation() {
    // 老人情况
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: "Measure",
          category: '11'
        }
      }).then(res => {
        this.setData({
          old_situation_list: res.data.result
        })
        reslove()
      })
    })
  },

  get_other_data() {
    // 其他福利
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: "Measure",
          category: '12'
        }
      }).then(res => {
        this.setData({
          other_data_list: res.data.result
        })
        reslove()
      })
    })
  },

  HouseClass() {
    // 家政员星级
    app.globalData.post({
      data: {
        do: "HouseClass"
      }
    }).then(res => {
      this.setData({
        star_list: res.data.data
      })
    })
  },

  change_types(e) {
    // if(e.currentTarget.dataset.index==2){
    //   wx.showToast({
    //     title: '暂无该类型家政员',
    //     icon:'none'
    //   })
    //   return
    // }
    this.setData({
      types_curr: e.currentTarget.dataset.index,
      work_type: e.currentTarget.dataset.index,
      child_work_type: -1,
    })
  },

  change_types_child(e) {
    this.setData({
      types_child_curr: e.currentTarget.dataset.index,
    })
  },

  change_zhujia(e) {
    this.setData({
      zhujia_curr: e.currentTarget.dataset.index,
      is_live_room: this.data.zhujia[e.currentTarget.dataset.index].type
    })
  },
  show_date() {
    this.setData({
      is_production: true
    })
  },


  chaneg_hygiene(e) {
    this.setData({
      hygiene_curr: e.currentTarget.dataset.index,
      measure: this.data.hygiene_list[e.currentTarget.dataset.index].title
    })
  },

  change_work_times_start(e) {
    this.setData({
      work_times_start: e.detail
    })
  },

  change_money(e) {
    // 工资范围
    // this.setData({
    //   money2: e.detail
    // })
    this.setData({
      money2: Number(e.detail.value),
      total: (Number(e.detail.value) * 0.15).toFixed(2)
    })
  },

  change_need_age(e) {
    this.setData({
      need_age: e.detail.value
    })
  },

  chaneg_taste(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      ['taste_list[' + index + '].select']: !this.data.taste_list[index].select
    })
    let arr = []
    this.data.taste_list.forEach((v, i) => {
      if (v.select) {
        arr.push(v.title)
      }
    })
    let val = '';
    if (arr.length > 0) {
      val = arr.join(',')
    }
    this.setData({
      diet: val
    })
  },

  chaneg_old_situation(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      ['old_situation_list[' + index + '].select']: !this.data.old_situation_list[index].select
    })
    let arr = []
    this.data.old_situation_list.forEach((v, i) => {
      if (v.select) {
        arr.push(v.title)
      }
    })
    let val = '';
    if (arr.length > 0) {
      val = arr.join(',')
    }
    this.setData({
      old_situation: val
    })
  },

  chaneg_other_data(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      ['other_data_list[' + index + '].select']: !this.data.other_data_list[index].select
    })
    let arr = []
    this.data.other_data_list.forEach((v, i) => {
      if (v.select) {
        arr.push(v.title)
      }
    })
    let val = '';
    if (arr.length > 0) {
      val = arr.join(',')
    }
    this.setData({
      other_data: val
    })
  },

  chaneg_star(e) {
    this.setData({
      star_curr: e.currentTarget.dataset.type,
      total: e.currentTarget.dataset.total,
    })
  },

  to_write(e) {
    wx.navigateTo({
      url: './write?val=' + e.currentTarget.dataset.val,
    })
  },

  getTime(e) {
    this.setData({
      worktime: e.detail
    })
  },

  to_store_user() {
    wx.navigateTo({
      url: './store_user',
    })
  },

  toMyAddress() {
    if (!this.data.is_store) {
      wx.navigateTo({
        url: '../matron/address?type=1',
      })
    } else {
      if (!this.data.store_to_user.id) {
        wx.showToast({
          title: '请先选择用户',
          icon: 'none'
        })
        return
      }
      wx.navigateTo({
        url: './address?id=' + this.data.store_to_user.id,
      })
    }
  },
  MyAddressInfo() { //选择地址
    getApp().globalData.post({
      data: {
        do: "MyAddressInfo",
        id: wx.getStorageSync('id')
      }
    }).then(res => {
      this.setData({
        myDefaultAddress: res.data,
        addressid: res.data.id
      })
    })
  },

  change_working_day(e) {
    this.setData({
      working_day_num: e.detail.value,
      working_day: this.data.working_day_list[e.detail.value]
    })
  },
  change_production_mode(e) {
    this.setData({
      production_mode_num: e.detail.value,
      production_mode: this.data.production_mode_list[e.detail.value].name
    })
  },
  change_fetus(e) {
    this.setData({
      fetus_num: e.detail.value,
      fetus: this.data.fetus_list[e.detail.value].name
    })
  },
  change_gznative_place(e) {
    this.setData({
      gznative_place_num: e.detail.value,
      gznative_place: this.data.gznative_place_list[e.detail.value].name
    })
  },
  change_education(e) {
    this.setData({
      education_num: e.detail.value,
      education: this.data.education_list[e.detail.value].id
    })
  },
  change_native_place(e) {
    this.setData({
      native_place_num: e.detail.value,
      native_place: this.data.native_place_list[e.detail.value].id
    })
  },
  change_sex(e) {
    this.setData({
      sex_num: e.detail.value,
      sex: this.data.sex_list[e.detail.value].id
    })
  },
  change_employment(e) {
    this.setData({
      employment_num: e.detail.value,
      employment: this.data.employment_list[e.detail.value].id
    })
  },
  change_work_experience(e) {
    this.setData({
      work_experience_num: e.detail.value,
      work_experience: this.data.work_experience_list[e.detail.value].id
    })
  },
  change_expectation(e) {
    this.setData({
      expectation: Number(e.detail.value) + 1,
    })
  },
  change_birthday(e) {
    this.setData({
      birthday: e.detail.value
    })
  },
  change_production(e) {
    this.setData({
      production: e.detail.value
    })
  },

  to_gqm() {
    wx.navigateTo({
      url: '/aunt/pages/handwriting/handwriting',
    })
  },



  bottomTap() {
    if (!is_auth(true)) {
      return false
    }
    if (this.data.work_type == -1) {
      wx.showToast({
        title: '请选择家政员类型',
        icon: 'none'
      })
      return
    }
    if (this.data.is_live_room == -1 && this.data.work_type != 3 && this.data.work_type != 6 || (this.data.work_type == 6 && this.data.types_child_list[this.data.types_child_curr].type != 3 && this.data.is_live_room == -1)) {
      wx.showToast({
        title: '请选择是否住家',
        icon: 'none'
      })
      return
    }
    // if (this.data.work_type == 6 && !this.data.old_situation) {
    //   wx.showToast({
    //     title: '请选择老人情况',
    //     icon: 'none'
    //   })
    //   return
    // }
    // if (this.data.work_type == 1 && !this.data.production) {
    //   wx.showToast({
    //     title: '请选择预产期或预计上户日期',
    //     icon: 'none'
    //   })
    //   return
    // }

    if (this.data.is_specia) {
      if (!this.data.production_mode) {
        wx.showToast({
          title: '请选择生产方式',
          icon: 'none'
        })
        return
      }
      if (!this.data.fetus) {
        wx.showToast({
          title: '请选择单双胞胎',
          icon: 'none'
        })
        return
      }
      if (!this.data.gznative_place) {
        wx.showToast({
          title: '请选择雇主籍贯',
          icon: 'none'
        })
        return
      }
    }

    if (!this.data.production && this.data.work_type == 1) {
      wx.showToast({
        title: '请选择预产期或预计上户日期',
        icon: 'none'
      })
      return
    }

    if (!this.data.work_times_start) {
      wx.showToast({
        title: '请选择工作时间',
        icon: 'none'
      })
      return
    }
    if (!this.data.work_do) {
      wx.showToast({
        title: '请输入工作内容',
        icon: 'none'
      })
      return
    }
    if (!this.data.can_do) {
      wx.showToast({
        title: '请输入任职要求',
        icon: 'none'
      })
      return
    }
    // if ((this.data.work_type == 1 || this.data.work_type == 2) && !this.data.persion_num_age) {
    //   wx.showToast({
    //     title: '请输入家庭人数及人员年龄',
    //     icon: 'none'
    //   })
    //   return
    // }
    if ((this.data.work_type == 1 || this.data.work_type == 2) && !this.data.measure) {
      wx.showToast({
        title: '请选择家庭卫生面积',
        icon: 'none'
      })
      return
    }

    // if ((this.data.work_type == 1 || this.data.work_type == 2) && !this.data.diet) {
    //   wx.showToast({
    //     title: '请选择口味要求',
    //     icon: 'none'
    //   })
    //   return
    // }

    if (!this.data.worktime) {
      wx.showToast({
        title: '请选择服务时间',
        icon: 'none'
      })
      return
    }

    if (!this.data.working_day) {
      wx.showToast({
        title: '请选择每月工作天数',
        icon: 'none'
      })
      return
    }

    if (!this.data.addressid) {
      wx.showToast({
        title: '请选择服务地址',
        icon: 'none'
      })
      return
    }

    if (!this.data.money2 && !this.data.is_specia) {
      wx.showToast({
        title: '请输入工资薪酬',
        icon: 'none'
      })
      return
    }
    if (this.data.money2 < 1000 && !this.data.is_specia) {
      wx.showToast({
        title: '工资薪酬需大于1000元',
        icon: 'none'
      })
      return
    }


    // if(!this.data.gqm){
    //   wx.showToast({
    //     title: '请先签名',
    //     icon: 'none'
    //   })
    //   return
    // }

    // if (this.data.star_curr == -1) {
    //   wx.showToast({
    //     title: '请选择家政员星级',
    //     icon: 'none'
    //   })
    //   return
    // }

    if (!this.data.flag) {
      return
    }

    this.setData({
      flag: false
    })
    let that = this

    let data = {
      uid: this.data.is_store ? this.data.store_to_user.id : wx.getStorageSync('userInfo').id,
      addressid: this.data.addressid,
      work_type: this.data.work_type,
      is_live_room: this.data.is_live_room,
      work_times_start: this.data.work_times_start,
      work_do: this.data.work_do,
      can_do: this.data.can_do,
      persion_num_age: this.data.persion_num_age,
      measure: this.data.measure,
      diet: this.data.diet,
      worktime: this.data.worktime,
      money2: this.data.money2,
      other_data: this.data.other_data,
      production: this.data.production,
      old_situation: this.data.old_situation,
      child_situation: this.data.child_situation,
      earnest_type: this.data.star_curr == -1 ? 4 : this.data.star_curr,
      earnest_price: this.data.total,
      openid: wx.getStorageSync('userInfo').openid,
      child_work_type: this.data.types_child_curr == -1 ? '' : this.data.types_child_list[this.data.types_child_curr].type,
      working_day: this.data.working_day,
      education: this.data.education,
      native_place: this.data.native_place,
      need_age: this.data.need_age,
      employment: this.data.employment,
      work_experience: this.data.work_experience,
      sex: this.data.sex,
      birthday: this.data.birthday,
      expectation: this.data.expectation,
      // gqm:this.data.gqm,
    }

    if (this.data.is_store) {
      getApp().globalData.gets('/api/ouyoung/work/oracleWork', {
        ...data,
        store_id: wx.getStorageSync('merchant').admin.storeid
      }).then(res => {
        getApp().showModal(res.data.msg).then(() => {
          if (res.data.code == 1) {
            wx.reLaunch({
              url: '/pages/index/blank',
            })
          } else {
            this.setData({
              flag: true
            })
          }
        })
      })
    } else if (this.data.is_specia) {
      app.globalData.post({
        data: {
          do: 'AddReleaseWorkSpecia',
          a: 'wxapp2',
          work_special_id: this.data.work_special_id,
          production_mode: this.data.production_mode,
          fetus: this.data.fetus,
          gznative_place: this.data.gznative_place,
          ...data,
        }
      }).then(res => {
        if (res.data.code == 1) {
          app.showModal('发布成功,请耐心等待家政员接单').then(() => {
            wx.navigateBack({
              delta: 1,
            })
          })
        } else {
          app.showModal(res.data.msg).then(() => {
            this.setData({
              flag: true
            })
          })
        }
      })
    } else {

      let paytype_list = this.data.paytype_list
      let itemList = []
      paytype_list.forEach((v, i) => {
        itemList.push(v.title)
      })
      app.globalData.post({
        data: {
          do: 'AddReleaseWorkV3',
          // paytype,
          ...data
        }
      }).then(res => {
        let data = res.data;

        if (res.data.code != 1) {
          getApp().showModal(res.data.msg).then(() => {
            this.setData({
              flag: true
            })
          })
          return
        }
        if (getApp().globalData.appletpayves_info.work == 3) {

          getApp().payPlugin(data.orderNo).then(() => {
            that.setData({
              flag: true
            })
            getApp().showModal('系统已为您自动推荐家政员', true, '立即查看').then(() => {
              wx.navigateTo({
                url: '/pages/matron/plan?wid=' + data.release_work_id
              })
            }).catch(() => {
              wx.navigateBack()
            })
          }).catch(() => {
            that.setData({
              flag: true
            })
          })
          return
        }
        if(res.data.code==1){
        
         app.showModal('发布成功，系统已为您自动推荐家政员', true, '立即查看').then(() => {
           wx.navigateTo({
             url: '/pages/matron/plan?wid=' + res.data.release_work_id
           })
         }).catch(() => {
           wx.navigateBack({
             delta: 1,
           })
         })
         return
       }
       

       
      })
      return
      wx.showActionSheet({
        itemList,
        success: (res) => {
          let tapIndex = res.tapIndex
          // let paytype = paytype_list[tapIndex].paytype
          let paytype = paytype_list[tapIndex].paytype

          if (paytype == 6) {
            wx.setStorageSync('pay_info', {
              do: 'AddReleaseWorkV3',
              paytype,
              ...data
            })
            wx.navigateTo({
              url: '/online_bank/list'
            })
            return
          }

          app.globalData.post({
            data: {
              do: 'AddReleaseWorkV3',
              paytype,
              ...data
            }
          }).then(res => {
            let data = res.data;

            if (res.data.code != 1) {
              getApp().showModal(res.data.msg).then(() => {
                this.setData({
                  flag: true
                })
              })
              return
            }
            if (getApp().globalData.appletpayves_info.work == 3) {

              getApp().payPlugin(data.orderNo).then(() => {
                that.setData({
                  flag: true
                })
                getApp().showModal('系统已为您自动推荐家政员', true, '立即查看').then(() => {
                  wx.navigateTo({
                    url: '/pages/matron/plan?wid=' + data.release_work_id
                  })
                }).catch(() => {
                  wx.navigateBack()
                })
              }).catch(() => {
                that.setData({
                  flag: true
                })
              })
              return
            }
            if(res.data.code==1){
            
             app.showModal('系统已为您自动推荐家政员', true, '立即查看').then(() => {
               wx.navigateTo({
                 url: '/pages/matron/plan?wid=' + res.data.release_work_id
               })
             }).catch(() => {
               wx.navigateBack({
                 delta: 1,
               })
             })
             return
           }
            // if (data.jump) {
            //   this.selectComponent('#zfb_pay').get_code(data.jump)
            //   this.setData({
            //     show_code_img: true,
            //     has_jump: true,
            //     flag: true,
            //     release_work_id: data.release_work_id
            //   })
            //   return
            // } else {
            //   this.setData({
            //     has_jump: false,
            //     flag: true,
            //     release_work_id: ''
            //   })
            // }
            // console.log("到这来了");
            // if (!data.package) {
            //   getApp().showModal('暂无法使用该支付方式，请选择其他支付方式', true).then(() => {
            //     this.RenewWork(e)
            //   })
            //   return
            // }

            wx.requestPayment({
              nonceStr: data.nonceStr,
              package: data.package,
              paySign: data.paySign,
              timeStamp: data.timeStamp,
              signType: data.signType,
              complete(s) {
                if ("requestPayment:ok" == s.errMsg) {
                  that.setData({
                    flag: true
                  })
                  app.showModal('系统已为您自动推荐家政员', true, '立即查看').then(() => {
                    wx.navigateTo({
                      url: '/pages/matron/plan?wid=' + data.release_work_id
                    })
                  }).catch(() => {
                    wx.navigateBack({
                      delta: 1,
                    })
                  })
                } else {
                  wx.showToast({
                    title: "支付失败",
                    icon: "none"
                  })
                  that.setData({
                    flag: true
                  })
                  return false
                }
              }
            })
          })

        }
      })


    }
  },

})